#include <stdio.h> // perror()
#include <fcntl.h> // open()
#include <stdlib.h> // exit()
#include <unistd.h> // read()/write()/close()


int main(int argc, char const *argv[])
{
    
    int fd1 = open("aa.txt", O_RDONLY); 
    // int fd2 =  open("bb.txt", O_WRONLY | O_CREAT  | O_TRUNC, 0644);
    int fd2 =  open("bb.txt", O_WRONLY | O_CREAT  | O_APPEND, 0644);
    if (fd1 == -1) {
        perror("open error");
        exit(1);
    }
    char buf[1024];
    int read_len = read(fd1, buf, 1024);
    while (read_len>0)
    {
         write(fd2, buf, read_len);
         //
         read_len = read(fd1, buf, 1024);
    }
    
    close(fd1);
    close(fd2);
    return 0;
}
